﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DAL = AccessDAL;

namespace BLL
{
    public class WebInfo
    {
        DAL.WebInfoTableAdapters.WebInfoTableAdapter DWI =
            new DAL.WebInfoTableAdapters.WebInfoTableAdapter();

        MODEL.WebInfo _MWI = new MODEL.WebInfo();


        #region GetDataByID
        /// <summary>
        /// GetDataByID
        /// </summary>
        /// <param name="MWI"></param>
        /// <returns></returns>
        public MODEL.WebInfo GetDataByID(MODEL.WebInfo MWI)
        {
            try
            {
                DataTable DT = DWI.GetDataByID(MWI.WI_ID);

                _MWI.WI_Content = DT.Rows[0]["WI_Content"].ToString();
                _MWI.WI_DateTime = Convert.ToDateTime(DT.Rows[0]["WI_DateTime"]);
                _MWI.WI_Hit = Convert.ToInt32(DT.Rows[0]["WI_Hits"]);
                _MWI.WI_ID = Convert.ToInt32(DT.Rows[0]["WI_ID"]);
                _MWI.WI_State = Convert.ToInt32(DT.Rows[0]["WI_State"]);
                _MWI.WI_Title = DT.Rows[0]["WI_Title"].ToString();

                return _MWI;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion


        #region 点击加1
        /// <summary>
        /// 点击加1
        /// </summary>
        /// <param name="MWI"></param>
        public void HitsPlus1(MODEL.WebInfo MWI)
        {
            try
            {
                DWI.HitsPlus1(MWI.WI_ID);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion


        #region 修改内容
        /// <summary>
        /// 修改内容
        /// </summary>
        /// <param name="MWI"></param>
        public void ModContentByID(MODEL.WebInfo MWI)
        {
            try
            {
                DWI.ModContentByID(MWI.WI_Content, MWI.WI_ID);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion


        #region 添加信息 [高级管理]
        public void Add(MODEL.WebInfo MWI)
        {
            try
            {
                DWI.Add(MWI.WI_Title,
                    MWI.WI_Content,
                    MWI.WI_DateTime,
                    MWI.WI_State,
                    MWI.WI_Hit);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion


        #region 修改信息 [高级管理]
        public void Mod(MODEL.WebInfo MWI)
        {
            try
            {
                if (MWI.WI_ID == 5)
                {
                    throw new Exception("此项目不可修改");
                }

                DWI.Mod(MWI.WI_Title, MWI.WI_Content, MWI.WI_ID);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion


        #region 删除信息 [高级管理]
        public void Del(MODEL.WebInfo MWI)
        {
            try
            {
                if (MWI.WI_ID < 6)
                {
                    throw new Exception("此项目不可删除");
                }

                DWI.Del(MWI.WI_ID);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
    }
}
